package com.biz.primus.management.tms.controller;

import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.management.tms.feign.DeliveryOrderFeignClient;
import com.biz.primus.model.tms.enums.DeliveryOrderStatus;
import com.biz.primus.model.tms.enums.SignType;
import com.biz.primus.model.tms.vo.DeliverySearchReqVo;
import com.biz.primus.model.tms.vo.DeliverySearchRespVo;
import com.biz.primus.model.tms.vo.LongitudeAndLatitudeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 配送单详情
 * Created by dylan on 17-1-21.
 */
@Controller
@RequestMapping("delivery")
//@Secured("ROLE_DELIVERY")
@Slf4j
public class DeliveryController {
    private static final int MAX_DOWNLOAD_DELIVER_COUNT = 250000;

    @Autowired
    private  DeliveryOrderFeignClient deliveryOrderFeignClient;




    /**
     * 根据条件查询对应订单列表
     */
    @GetMapping(value = "page")
    @PreAuthorize("hasAuthority('OPT_DELIVERY_LIST')")
    public ModelAndView searchPageDelivery(@ModelAttribute("reqVo") DeliverySearchReqVo reqVo) {
        ModelAndView mv = new ModelAndView("delivery/page");
        DeliveryOrderStatus[] shipStatus = DeliveryOrderStatus.values();
        SignType[] signTypes = SignType.values();
        SpringPageVO<DeliverySearchRespVo> springPage = deliveryOrderFeignClient.searchPageDelivery(reqVo);
        mv.addObject("page", springPage);
        mv.addObject("shipStatus", shipStatus);
        mv.addObject("signTypes", signTypes);
        return mv;
    }


    /**
     * 获取轨迹
     */
    @ResponseBody
    @RequestMapping(value = "getMaps")
    public List<LongitudeAndLatitudeVo> getMaps(String entityName, String startDate, String endDate) {
        return deliveryOrderFeignClient.getMaps(entityName, startDate, endDate);
    }

}
